package com.csist.filter;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam;

/**
 * 
 * @ClassName: CharsetFilter
 * @Description: �ַ�����������ͳһ���ַ�
 * @author: Mr.Tao
 * @date: 2021��11��22������8:29:09
 * @version: V1.0
 *
 */
@WebFilter(description = "�ַ���������", 
			urlPatterns = { "/*"}, 
			initParams = { @WebInitParam(name = "charset", value = "utf-8", description = "�ַ���Ϊutf-8��ȷ��֧�����ĺ���") }
		  )
public class CharsetFilter implements Filter {

	private String charset;

	/**
	 * Default constructor.
	 */
	public CharsetFilter() {
	}

	/**
	 * @see Filter#destroy()
	 */
	public void destroy() {
	}

	/**
	 * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
	 */
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		
		//���е��������������Ϊͳһ���ַ���
		request.setCharacterEncoding(this.charset);
		response.setCharacterEncoding(this.charset);
		chain.doFilter(request, response);
	}

	/**
	 * @see Filter#init(FilterConfig)
	 */
	public void init(FilterConfig fConfig) throws ServletException {
		this.charset=fConfig.getInitParameter("charset");
	}

}
